#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main()
{
	int x;
	string s;
	cin >> x >> s;
	int ret = stoi(s, NULL, x);
	cout << ret << endl;
//	int ret = x_to_ten(x, s);
//	cout << ret << endl;
	
	return 0;
}

int x_to_ten(int x, string s)
{
	size_t n = s.size();
	int j = 0, sum = 0;
	for (int i = n - 1; i >= 0; i--)
	{
		if (s[i] <= '9')
			sum += (s[i] - '0') * pow(x, j);
		else
			sum += (s[i] - 'A' + 10) * pow(x, j);
		j++;
	}
	return sum;
}


